package com.dayaokeji.imkitwrapper.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.dayaokeji.imkitwrapper.bean.Conversation;
import com.dayaokeji.imkitwrapper.view.ConversationView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * ********************************************************************
 * *  Created by Zeno on 2018/6/23
 * ********************************************************************
 * *  version 1.0
 * ********************************************************************
 * *  Copyright (C) dayaokeji.com 2018 -- 2020 All rights reserved.
 * ********************************************************************
 * * conversations adapter
 * ********************************************************************
 */
public class ConversationAdapter extends BaseAdapter {

    private List<Conversation> conversations;
    private Context context;

    public ConversationAdapter(Context context) {
        this.context = context;
    }

    public void setConversations(List<Conversation> conversations) {
        this.conversations = conversations;
    }

    @Override
    public int getCount() {
        return conversations.size();
    }
    @Override
    public Object getItem(int position) {
        return conversations.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ConversationView view = null;
        if (convertView == null) {
            view = new ConversationView(context);
        } else {
            view = (ConversationView)convertView;
        }
        Conversation c = conversations.get(position);
        view.setConversation(c);;
        return view;
    }
}